| ||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report this article. IntroductionThe attached source code is for a system-wide global hotkey control written in Visual Basic 6, orginally posted on the Merrion Computing Downloads Registering a hotkeyThere are two API calls concerned with registering a system wide hotkey: RegisterHotkey abd UnregisterHotkey - the declaratiosn are:
To register the hotkey you need to specify hwnd - the window which will be notified when the hotkey combination is pressed, id - the unique identifier for the hotkey, fsModifiers - the modifiers of the hotkey (i.e. whether ALT, SHIFT, CTRL or WIN keys are pressed) and finally vKey - the virtual key code for the hot key. The modifiers which can be combined together are:
Listening out for the hotkeyWhen a hotkey which has been registered successfully is pressed, the window specified in the hwnd is posted a WM_HOTKEY registered window message. Additionally the lParam parameter holds the modifier and virtual key code in it's high and low words respectively
Visual Basic does not handle the WM_HOTKEY message by default which means that you need to subclass the window hwnd in order to respond to it. To do this you use the API call SetWindowLong with the index GWL_WNDPROC to replace the existing window procedure with your one.
Using the control in your applicationTo use this control in a Visual basic application, compile the attached source code and then add an instance of the resulting OCX to your project. Add an instance of the MCLHotkey control to your form and press F4 to set the properties. Then add the code that you want executed when the hotkey is pressed to the HotkeyPressed event:
About Duncan Edwards Jones
| ||||||||||||||||||||||||||||||||||||||||||||
|
|
General comment
News / Info
Question
Answer
Joke / Game
Admin message
| All Topics, ASP.NET >> VB / VBScript >>
Unedited
Reader Contributions Updated: 13 May 2003 |
Article content
copyright Duncan Edwards Jones, 2003 everything else Copyright © CodeProject, 1999-2006. Web02 | Advertise on The Code Project | Privacy |
| The Ultimate Toolbox ASP Alliance Developer Fusion Developersdex DevGuru Programmers Heaven Planet Source Code Tek-Tips Forums |